package com.aaa.controller;
import com.aaa.common.domain.RentOutContractCURDInfo;
import com.aaa.common.domain.RentOutContractInfo;
import com.aaa.common.domain.comboboxquery.*;
import com.aaa.common.query.ConditionalQuery;
import com.aaa.common.query.PageQuery;
import com.aaa.common.query.ReminderContractConditionalQuery;
import com.aaa.common.result.Result;
import com.aaa.service.impl.*;
import com.aaa.service.impl.comboboxserviceimpl.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: 宋文森
 * @Date: 2021/01/26/14:39
 * @Description: 资产出租合同业务
 */
@RestController
@RequestMapping("/contract")
public class RentOutContractInfoController {

    /**
     * 公共依赖
     */
    @Autowired
    private LessorQueryServiceImpl lessorQueryService;
    @Autowired
    private PayMethodQueryServiceImpl payMethodQueryService;
    @Autowired
    private RentReceiveStatusServiceImpl rentReceiveStatusService;
    @Autowired
    private ContractStatusServiceImpl contractStatusService;
    @Autowired
    private BusinessStatusServiceImpl businessStatusService;
    @Autowired
    private RentOutContractInfoUpdateServiceImpl rentOutContractInfoUpdateService;//资产出租合同信息修改服务
    @Autowired
    private RentOutContractAddServiceImpl rentOutAddService;
    @Autowired
    private AssetTypeServiceImpl assetTypeService;


    /**
     * 自有资产出租合同所注入的依赖
     */
    @Autowired
    private OwnAssetsContractServiceImpl ownContractService;



    /**
     * 公有资产出租合同所注入的依赖
     */
    @Autowired
    private PublicAssetsContractServiceImpl publicContractService;


    /**
     * 其他资产出租合同注入的依赖
     */
    @Autowired
    private OtherAssetsContractServiceImpl otherAssetsContractService;

    /**
     * 合同到期提醒注入的依赖
     */
    @Autowired
    private ContractReminderServiceImpl contractReminderService;



    /** 公共方法
     * 资产出租合同添加操作的下拉框查询（查询所有的出租方，查询支付的可能方式，查询租金收取可能的情况，查询合同的可能状态，查询经营的可能状态,查询资产类型 ）
     * @return
     */
    @GetMapping("/listLessor")
    public Result listLessor(){
        List<LessorInfo> lessorInfos = lessorQueryService.ListLessor();
      if (lessorInfos.size()>0){
            return Result.success(lessorInfos);
        }
        return Result.error("下拉框查询失败");
    }

    @GetMapping("/payMethodInfos")
    public Result payMethodInfos(){
        List<PayMethodInfo> payMethodInfos = payMethodQueryService.listPayMethods();
        if (payMethodInfos.size()>0){
            return Result.success(payMethodInfos);
        }
        return Result.error("支付方式查询失败!");
    }

    @GetMapping("/rentReceiveStatusInfos")
    public Result rentReceiveStatusInfos(){
        List<RentReceiveStatusInfo> rentReceiveStatusInfos = rentReceiveStatusService.listStatus();
        if (rentReceiveStatusInfos.size()>0){
            return Result.success(rentReceiveStatusInfos);
        }
        return Result.error("租金收取状态查询失败!");
    }

    @GetMapping("/contractStatusInfos")
    public Result contractStatusInfos(){
        List<ContractStatusInfo> contractStatusInfos = contractStatusService.listContractStatus();
        if (contractStatusInfos.size()>0){
            return Result.success(contractStatusInfos);
        }
        return Result.error("合同状态查询失败!");
    }

    @GetMapping("/businessStatuses")
    public Result businessStatuses(){
        List<BusinessStatus> businessStatuses = businessStatusService.listBusinessStatus();
        if (businessStatuses.size()>0){
            return Result.success(businessStatuses);
        }
        return Result.error("经营状态查询失败!");
    }

    @GetMapping("/listAssetType")
    public Result listAssetType(){
        List<AssetType> assetTypes = assetTypeService.listAssetTypes();
        if (assetTypes!=null){
            return Result.success(assetTypes);
        }
        return Result.error("资产类型查询失败！");
    }


    /**公共方法
     * 资产出租合同删除（根据合同的id进行删除）
     * @param id
     * @return
     */
    @GetMapping("/deleteRentOutContractById")
    public Result rentOutContractDelete( int id){
        return rentOutContractInfoUpdateService.rentOutContractDelete(id);

    }


    /**
     * 查询所有的自有资产租出的合同信息
     * @param pageQuery
     * @return
     */
    @PostMapping("/listOwnContract")
    public Result listAll(@RequestBody PageQuery pageQuery){
        return ownContractService.listAll(pageQuery);
    }

    /**
     * 自有资产出租合同的条件查询
     * @param conditionalQuery
     * @return
     */
    @PostMapping("/listOwnContractQuery")
    public Result conditionalQuery(@RequestBody ConditionalQuery conditionalQuery){

        return ownContractService.conditionalQuery(conditionalQuery);
    }




    /**
     * 自有租出合同的添加操作
     * @param rentOutContractCURDInfo
     * @return
     */
    @PostMapping("/listOwnContract/listComBoBoxQuery/insertOwnRentOut")
    public Result insert(@Validated @RequestBody RentOutContractCURDInfo rentOutContractCURDInfo){

        return rentOutAddService.insert(rentOutContractCURDInfo);

    }


    /**
     *自有资产租出合同的修改操作 (包括修改前的查询操作)
     * @param id
     * @return
     */

    @GetMapping("/listContract/updateContract/listOne")
    public Result rentOutContractListOne(  int id){
        return rentOutContractInfoUpdateService.rentOutContractListOne(id);
    }

    @PostMapping("/listOwnContract/updateOwnContract")
    public Result updateOwnContract(@RequestBody RentOutContractInfo rentOutContractInfo){
        return  rentOutContractInfoUpdateService.rentOutContractUpdate(rentOutContractInfo);
    }


    /**
     * 查询所有公有资产出租合同的信息
     * @param pageQuery
     * @return
     */
    @PostMapping("/listPublicContract")
    public Result listPublicContract(@RequestBody PageQuery pageQuery){
       return publicContractService.listAll(pageQuery);
    }


    /**
     * 公有资产出租合同的条件查询
     * @param conditionalQuery
     * @return
     */
    @PostMapping("/listPublicContract/query")
    public Result publicContractQuery(@RequestBody ConditionalQuery conditionalQuery){

      return   publicContractService.conditionalQuery(conditionalQuery);
    }

    /**
     * 公有资产出租合同的添加
     * @param rentOutContractCURDInfo
     * @return
     */
    @PostMapping("/listPublicContract/listComBoBoxQuery/insertPublicContract")
    public Result insertPublicContract(@RequestBody RentOutContractCURDInfo rentOutContractCURDInfo){
        return  rentOutAddService.insert(rentOutContractCURDInfo);
    }

    /**
     *公有资产租出合同的修改操作
     * @param rentOutContractInfo
     * @return
     */


    @PostMapping("/listPublicContract/updatePublicContract")
    public Result updatePublicContract(@RequestBody RentOutContractInfo rentOutContractInfo){
        return  rentOutContractInfoUpdateService.rentOutContractUpdate(rentOutContractInfo);
    }



    /**
     * 查询所有其他资产出租合同的信息
     * @param pageQuery
     * @return
     */
    @PostMapping("/listOtherAssetsContract")
    public Result listOtherAssetsContract(@RequestBody PageQuery pageQuery){
        return otherAssetsContractService.listAll(pageQuery);
    }


    /**
     * 其他资产出租合同的条件查询
     * @param conditionalQuery
     * @return
     */
    @PostMapping("/listOtherAssetsContract/query")
    public Result otherAssetsContractQuery(@RequestBody ConditionalQuery conditionalQuery){
        return   otherAssetsContractService.conditionalQuery(conditionalQuery);
    }

    /**
     * 其他资产出租合同的添加操作
     * @param rentOutContractCURDInfo
     * @return
     */
    @PostMapping("/listOtherAssetsContract/insertOtherAssetsContract")
    public Result insertOtherAssetsContract(@RequestBody RentOutContractCURDInfo rentOutContractCURDInfo){
        return rentOutAddService.insert(rentOutContractCURDInfo);
    }


    /**
     *其他资产租出合同的修改操作
     * @param rentOutContractInfo
     * @return
     */
    @PostMapping("/listOtherAssetsContract/updateOtherAssetsContract")
    public Result updateOtherAssetsContract(@RequestBody RentOutContractInfo rentOutContractInfo){
        return  rentOutContractInfoUpdateService.rentOutContractUpdate(rentOutContractInfo);
    }

    /**
     * 租出合同到期提醒相关信息的查询
     * @param pageQuery
     * @return
     */
    @PostMapping("/listRentOutContract")
    public Result listRentOutContract(@RequestBody PageQuery pageQuery){
      return   contractReminderService.listRentOutContractReminder(pageQuery);
    }

    /**
     * 租出合同到期提醒的下拉框查询信息
     * @return
     */
    @GetMapping("/listRentOutContract/listCompanyName")
    public Result listCompanyName(){
        return contractReminderService.listCompanyName();
    }

    /**
     * 租出合同到期提醒的条件查询
     * @param reminderContractConditionalQuery
     * @return
     */
    @PostMapping("/listRentOutContract/RentOutContractConditionalQuery")
    public Result RentOutContractConditionalQuery(@RequestBody ReminderContractConditionalQuery reminderContractConditionalQuery){
      return   contractReminderService.RentOutContractConditionalQuery(reminderContractConditionalQuery);
    }








}
